from django.core.management.base import BaseCommand
from apps.oaauth.models import OAUser, OAUserManager, OADepartment


class Command(BaseCommand):
    def handle(self, *args, **options):

        boarder = OADepartment.objects.get(name="董事会")
        developer = OADepartment.objects.get(name="产品开发部")
        operator = OADepartment.objects.get(name="运营部")
        saler = OADepartment.objects.get(name="销售部")
        hr = OADepartment.objects.get(name="人事部")
        finance = OADepartment.objects.get(name="财务部")

        #1.东东--董事会leader
        dongdong = OAUser.objects.create_superuser(email="dongdong@qq.com",realname="东东",password="dongdong",department=boarder)
        #2.多多--董事会leader
        duoduo = OAUser.objects.create_superuser(email="duoduo@qq.com",realname="多多",password="duoduo",department=boarder)
        #3.张三--产品开发部leader
        zhangsan = OAUser.objects.create_user(email="zhangshan@qq.com",realname="张三",password="zhangsan",department=developer)
        #4.李四--运营部leader
        lisi = OAUser.objects.create_user(email="lisi@qq.com",realname="李四",password="lisi",department=operator)
        #5.王五--销售部leader
        wangwu = OAUser.objects.create_user(email="wangwu@qq.com",realname="王五",password="wangwu",department=saler)
        #6.赵六--人事部leader
        zhaoliu = OAUser.objects.create_user(email="zhaoliu@qq.com",realname="赵六",password="zhaoliu",department=hr)
        #6.孙七--财务部leader
        sunqi = OAUser.objects.create_user(email="sunqi@qq.com",realname="孙七",password="sunqi",department=finance)

        boarder.leader = dongdong
        boarder.managers = None
        boarder.save()

        developer.leader = zhangsan
        developer.managers = dongdong
        developer.save()

        operator.leader = lisi
        operator.managers = dongdong
        operator.save()

        saler.leader = wangwu
        saler.managers = dongdong
        saler.save()

        hr.leader = zhaoliu
        hr.managers = duoduo
        hr.save()

        finance.leader = sunqi
        finance.managers = duoduo
        finance.save()


        self.stdout.write('用户创建成功')
